import { defineStore } from 'pinia'
import api from '../../api/daily'
import { findData } from './types'
export default defineStore('store', {
  actions: {
    //每日一练 查询题目列表
    async getContentList(condition: findData, id: any) {
      const { data } = await api.listAll(condition, id)
      return { data }
    },
    //每日一练 做题记录同步到t_exam_record表中
    async addRecord(rightValue: any) {
      const { data } = await api.addExamRecord(rightValue)
      return { data }
    },
    //用户答题记录
    async getRecords(value: String) {
      const { data } = await api.listRecords(value)
      return { data }
    },
    //导出答题记录
    async exportRecords(value: string) {
      const res = await api.exportExamRecord(value)
      // new Blob([data])用来创建URL的file对象或者blob对象
      const url = window.URL.createObjectURL(
        new Blob([res], { type: 'application/vnd.ms-excel;charset=utf-8' })
      ) // 生成一个a标签
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      link.download = '做题记录'
      link.click()
      URL.revokeObjectURL(link.href) //移除链接
    }
  }
})
